import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { QrcodeVO, QrcodeForm, QrcodeQuery } from '@/api/sj/qrcode/types';

/**
 * 查询二维码管理列表
 * @param query
 * @returns {*}
 */

export const listQrcode = (query?: QrcodeQuery): AxiosPromise<QrcodeVO[]> => {
  return request({
    url: '/sj/qrcode/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询二维码管理详细
 * @param id
 */
export const getQrcode = (id: string | number): AxiosPromise<QrcodeVO> => {
  return request({
    url: '/sj/qrcode/' + id,
    method: 'get'
  });
};

/**
 * 新增二维码管理
 * @param data
 */
export const addQrcode = (data: QrcodeForm) => {
  return request({
    url: '/sj/qrcode',
    method: 'post',
    data: data
  });
};

/**
 * 修改二维码管理
 * @param data
 */
export const updateQrcode = (data: QrcodeForm) => {
  return request({
    url: '/sj/qrcode',
    method: 'put',
    data: data
  });
};

/**
 * 删除二维码管理
 * @param id
 */
export const delQrcode = (id: string | number | Array<string | number>) => {
  return request({
    url: '/sj/qrcode/' + id,
    method: 'delete'
  });
};

/**
 * 生成二维码
 * @param id
 */
export const generateQrcode = (id: number | string) => {
  return request({
    url: 'sj/qrcode/generateQRCode/' + id,
    method: 'get'
  });
};

/**
 * 下载预览二维码
 * @param id
 */
export const downloadQrcode = (id: number | string) => {
  return request({
    url: '/resource/oss/download/' + id,
    method: 'get',
    responseType: 'blob'
  });
};

/**
 * 获取二维码url
 * @param id
 */
export const checkQrCode = (id: string) => {
  return request({
    url: 'resource/oss/preview/' + id,
    method: 'get'
  });
};
